﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CoVanHocTapData.Entities;

using CoVanHocTapData.Concretes;
using CoVanHocTapData.Interface;
using CoVanHocTapProject.Controllers;
using System.Web.Mvc;


namespace CoVanHocTapProject.Infrastructure
{
    public class Publics
    {
        #region repos
        static IHocKyRepository hocKyRepos = new HocKyRepository();
        static SinhVien_TichLuyRepositpry sv_TichLuyRepos = new SinhVien_TichLuyRepositpry();
        static IMenuRepository menuRepos = new MenuRepository();
        #endregion

        public static bool KiemTraHienThiDangKyKHHT
        {
            get { return menuRepos.KiemTraChoPhepDKMHTheoKHHT(); }
        }

        public static List<SelectListItem> hocKyList
        {
            get
            {
                if (HttpContext.Current.Session["hocKyList"] == null)
                    return new List<SelectListItem>();
                return (List<SelectListItem>)(HttpContext.Current.Session["hocKyList"]);
            }
            set
            {
                HttpContext.Current.Session["hocKyList"] = value;
            }
        }

        public static List<SinhVien_TichLuyKhoi> DSSVTichLuyKhoiTheoMonHoc
        {
            get
            {
                if (HttpContext.Current.Application["DSSVTLKhoi"] == null)
                    return null;
                return (List<SinhVien_TichLuyKhoi>)(HttpContext.Current.Application["DSSVTLKhoi"]);
            }
            set
            {
                HttpContext.Current.Session["DSSVTLKhoi"] = value;
            }
        }

        public static HocKy hocKyHienTai
        {
            get {
                HocKy hk;
                //if (HttpContext.Current.Application["HocKyHienTai"] == null)
                //{
                    hk = hocKyRepos.LayHocKyHienTai();
                    HttpContext.Current.Application["HocKyHienTai"] = hk;
                //}
                //else
                //    hk = HttpContext.Current.Application["HocKyHienTai"] as HocKy;
                return hk;
            }
            
        }

        public static NguoiDung adminDangNhap
        {
            get {
                if (HttpContext.Current.Session["AdminDN"] == null)
                    return null;
                return (NguoiDung)(HttpContext.Current.Session["AdminDN"]);
            }
            set { HttpContext.Current.Session["AdminDN"] = value; }
        }

        public static SinhVien sinhVienDangNhap
        {
            get
            {
                if (HttpContext.Current.Application["SinhVienDN"] == null)
                    return null;
                return (SinhVien)(HttpContext.Current.Application["SinhVienDN"]);
            }
            set
            {
                HttpContext.Current.Application["SinhVienDN"] = value;
            }
        }

        public static bool LaSVYeuKem
        {
            get
            {
                if (sv_TichLuyRepos.LaSinhVienYeuKem(Publics.sinhVienDangNhap, Publics.hocKyHienTai.HocKyID))
                {
                    HttpContext.Current.Application["LaSVYeuKem"] = true;
                    return true;
                }
                return false;
            }
        }

        public static bool IsLogin()
        {
            return (Publics.sinhVienDangNhap != null);
        }

        public static void ClearSession()
        {
            HttpContext.Current.Session.Clear();
        }

        public static void Logout()
        {
            Publics.sinhVienDangNhap = null;
            KeHoachHocTapController.list = null;
        }

        public static string ClientMessageBox(string msg)
        {
            return "<script language='javascript'>alert('" + msg.Replace("\r\n", "\n").Replace("\n", "\\n") + "');</script>";
        }


        //import
        public static string Connection
        {
            get
            {
                //return @"Data Source=221.132.37.64\sqlexpress;Initial Catalog=TDT_EduProject;Persist Security Info=True;User ID=sa;Password=@TDT2@123#@;MultipleActiveResultSets=True";
                return System.Configuration.ConfigurationManager.ConnectionStrings["connectSQL"].ConnectionString;
            }
        }


        
    }
}